package cn.wk.controller;

import cn.wk.domain.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 生产者
 */
@RestController
@RequestMapping("/provider/user")
public class ProviderController {

    @RequestMapping("/{id}")
    @HystrixCommand(fallbackMethod = "getFallback")
    public User getUser(@PathVariable("id") Long id){
        if(id % 2 ==0){
            throw new RuntimeException("服务异常");
        }
        return new User(id,"小明"+id);
    }

    public User getFallback(Long id){
        return new User(null, "这里走了fallback");
    }
}
